//设置管理员
$(function(){
    $(".Set-admin-btn").on("click",function(){
        var setadminid = $(this).attr('set_adminid');
        $.ajax({
            type:'post',
            url: '/admin/user/set_admin',
            data:{
                setadminid:setadminid
            },
            dataType:'json',
            success: function(result) {
                if (!result.code) {
                    adminHint(result.message);
                    setTimeout(function(){
                        window.location.reload();
                    },1000);
                }
            }
        })
    })

    function adminHint(hint){
        $("#admin-hint").addClass('on');
        $("#admin-hint").html(hint);
        setTimeout(function(){
            $("#admin-hint").removeClass('on');
            $("#admin-hint").html('');
        },1000);
    }




    //添加内容
    var content_add = $('#content_add');
    content_add.find('#content_add_sub').on('click',function(){

        var category = content_add.find('[name="category"]').val(),
            title = content_add.find('[name="title"]').val(),
            abstract = content_add.find('[name="abstract"]').val(),
            editorValue = UE.getEditor('editor').getContent();
        $.ajax({
            type:'post',
            url: '/admin/content/add',
            data:{
                category:category,
                title:title,
                abstract:abstract,
                editorValue:editorValue
            },
            dataType:'json',
            success: function(result) {
                if(!result.code){
                    alert(result.message);
                    window.document.location.href="/admin/content";
                }
            }
        })
    })

    //修改内容
    var edit = $("#edit_centent");
    edit.find('#content_edit_sub').on('click',function(){
        var contentid = edit.find('[name="contentid"]').val(),
            category = edit.find('[name="category"]').val(),
            title = edit.find('[name="title"]').val(),
            abstract = edit.find('[name="abstract"]').val(),
            editorValue = UE.getEditor('editor').getContent();
        $.ajax({
            type:'post',
            url: '/admin/content/edit',
            data:{
                contentid:contentid,
                category:category,
                title:title,
                abstract:abstract,
                editorValue:editorValue
            },
            dataType:'json',
            success: function(result) {
                if(!result.code){
                    alert(result.message);
                    window.document.location.href="/admin/content";
                }
            }
        })
    })
})
